* Multiproduct Firms, Horizontal Mergers, and International Trade
* Jackie M.L. Chan, Michael Irlacher, and Michael Koch

* This do file sets up the dataset used for the regression analysis of domestic market outcomes with the synthetic merger control group.

foreach v in 3c 4c 9c{
	
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_dom_mergers_synthetic_02102023_v`v'.dta", clear 

* Create panel for each merger event
keep cvrnrA aar merger
duplicates drop
expand 7
bysort cvrnrA aar: gen d_yr = _n - 4
gen aarA = aar + d_yr

* Merge with acquirer firm characteristics
rename cvrnrA cvrnr
rename aar aar_ori
rename aarA aar
merge 1:1 cvrnr aar using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_firm_subset1865.dta", keepusing(aar employee_cvrnr CVR_BRANCHE_DB93 CVR_BRANCHE_DB07)

* Only keep relevant firms in this sample, drop all other firms
egen max_merge = max(_merge), by(cvrnr)
keep if max_merge==3
drop max_merge

rename aar aarA
rename aar_ori aar
keep cvrnr aar d_yr aarA employee_cvrnr CVR_BRANCHE_DB07 merger
egen acquirer = max(merger), by(cvrnr)
drop merger

* Match to VARS data
rename cvrnr cvrnrA
merge 1:1 cvrnrA aarA using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_vars_dom_all_cvrnr_dro.dta", keep(match master) nogen

foreach x in nprod vrdA max_vrdA med_vrdA min_vrdA{
	replace `x' = 0 if `x'==.
	}

gen lnnprod = ln(nprod)
gen lnvrdA = ln(vrdA)
gen lnrev_max=ln(max_vrdA)
gen lnrev_med=ln(med_vrdA)
gen lnrev_min=ln(min_vrdA)

* Indicator for each Indexvalue, except 0 (reference year)
foreach i of numlist 1(1)3{
gen m`i'=0
replace m`i'=1 if d_yr==-`i'
}

foreach i of numlist 1(1)3 {
gen p`i'=0
replace p`i'=1 if d_yr==`i'
}

gen test=0

gen ind=floor(CVR_BRANCHE_DB07/10000)

drop if aarA<1996

egen group_cvrnr = group(cvrnr)
compress
save "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_did_imputation_vars_dom_prepare_jc_synthetic_02102023_v`v'.dta", replace
}
